package typejump.objects;

import typejump.AnimationManager;
import typejump.Settings;
import typejump.engine.CollisionProps;
import typejump.engine.GameEngine;

public class Player extends Actor {
	
	public Player() {
		super("Player");
		setCollision(CollisionProps.T_PC, CollisionProps.T_ITEM|CollisionProps.T_GEOM);
		setMaxHealth(100);
		setDamageInterval(0.5);
	}
	
	public String generateSpawnCommand() {
		return width() + " " + height();
	}
	
	public static Player createObject(String params) {
		Player p = new Player();
		if (params.matches("[-\\.0-9]+ [-\\.0-9]+")) {
			p.width( Double.parseDouble(params.substring(0, params.indexOf(' '))));
			p.height(Double.parseDouble(params.substring(params.indexOf(' ')+1)));
		}
		return p;
	}
	
	public boolean damage(double d) {
		boolean b = super.damage(d);
		if (b) {
			Sparkles sparkles = new ExplodingSparkles(this, AnimationManager.SWAG_DROP);
			sparkles.setAcceleration(0, Settings.getDouble("bloodgravity"));
			GameEngine.addEffect(sparkles);
		}
		return b;
	}
	
	public void die() {
		super.die();
		
		Sparkles sparkles = new ExplodingSparkles(this, AnimationManager.SWAG_DROP);
		sparkles.setAcceleration(0, Settings.getDouble("bloodgravity"));
		GameEngine.addEffect(sparkles);
	}
}
